package cn.cloud.all.security.web.authentication;

import cn.cloud.all.security.core.AuthenticationException;
import cn.cloud.all.security.web.AuthenticationEntryPoint;
import org.springframework.http.HttpStatus;
import org.springframework.util.Assert;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public final class HttpStatusEntryPoint implements AuthenticationEntryPoint {

    private final HttpStatus httpStatus;

    public HttpStatusEntryPoint(HttpStatus httpStatus) {
        Assert.notNull(httpStatus, "httpStatus cannot be null");
        this.httpStatus = httpStatus;
    }

    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) {
        response.setStatus(httpStatus.value());
    }
}
